package controller;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import model.Model;
import model.TokboxDAO;
import model.UserDAO;

import databean.Tokbox;
import databean.User;


public class VideoExistingConfsAction extends Action {
	
	
	private TokboxDAO tokboxDAO;
	private UserDAO   userDAO;


	public VideoExistingConfsAction(Model model) {
		tokboxDAO = model.getTokboxDAO();
		userDAO   = model.getUserDAO();
	}

	public String getName() { return "video-existing-confs.do"; }

	public String perform(HttpServletRequest request,HttpServletResponse response) {
        
		// Set up the errors list
        List<String> errors = new ArrayList<String>();
        request.setAttribute("errors",errors);
        
        HttpSession session = request.getSession();
        
		try {
	        
			if (session.getAttribute("user") == null) {
				return "user-login.do";
			}
	        
			request.setAttribute("user",(User) request.getSession(false).getAttribute("user"));
			
			
			//get a list of existing video conferences
		    ArrayList<Tokbox> tokboxes = tokboxDAO.getAllConfs();
		    request.removeAttribute("tokboxes");
		    request.setAttribute("tokboxes",tokboxes);
		    
		    ArrayList<User> users = userDAO.getAllUsers();
		    request.removeAttribute("users");
		    request.setAttribute("users",users);


	        return "video-existing-confs.jsp";
	        
	        
        } catch (Exception e) {
        	errors.add(e.getMessage());
        	return "user-login.do";
        }
        
    }
}



